package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.PictureAddNewDTO;
import cn.tedu.csmall.product.service.impl.PictureServiceImpl;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 处理图片类请求的控制器
 */
@Slf4j
@RestController
@RequestMapping("/pictures")
@Api(tags = "07.图片管理模块")
public class PictureController {

    @Autowired
    PictureServiceImpl service;

    @PostMapping("add-new")
    @ApiOperation(value = "添加图片")
    @ApiOperationSupport(order = 101)
    public JsonResult<Void> addNew(PictureAddNewDTO dto){
        log.debug("开始处理[添加图片]的请求, 参数:{}", dto);
        service.addNew(dto);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation(value = "删除图片")
    @ApiOperationSupport(order = 201)
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("开始处理[删除图片]的请求, 参数:{}", id);
        service.delete(id);
        return JsonResult.ok();
    }
}
